/**
 * 
 */
package com.zxc.furyio;

import java.util.Map;

import com.alibaba.fastjson.JSON;

import cn.hutool.core.map.MapUtil;
import io.fury.Fury;
import io.fury.Language;
import io.fury.ThreadSafeFury;

/**
 * @author Administrator
 *
 */
public class FuryioDemo {

	public static class SomeClass {
		SomeClass f1;
		Map<String, String> f2;
		Map<String, String> f3;
		public SomeClass getF1() {
			return f1;
		}
		public void setF1(SomeClass f1) {
			this.f1 = f1;
		}
		public Map<String, String> getF2() {
			return f2;
		}
		public void setF2(Map<String, String> f2) {
			this.f2 = f2;
		}
		public Map<String, String> getF3() {
			return f3;
		}
		public void setF3(Map<String, String> f3) {
			this.f3 = f3;
		}
	}

	public static Object createObject() {
		SomeClass obj = new SomeClass();
		obj.f1 = obj;
		obj.f2 = MapUtil.of("key", "value");
		obj.f3 = obj.f2;
		return obj;
	}

	public static void main(String[] args) {
		ThreadSafeFury fury = Fury.builder()
				.withLanguage(Language.JAVA)
				.withRefTracking(true)
				.withSecureMode(false)// 允许反序列化未知类型，不安全，但更灵活,
				.buildThreadSafeFury();
		byte[] bytes = fury.serialize(createObject());
		Object obj = fury.deserialize(bytes);
		System.out.println(JSON.toJSONString(obj));
	}
}
